package com.itlong.cloud.sdk.service.impl;

import com.itlong.cloud.POJO.PO.RoomInfoPO;
import com.itlong.cloud.PlatformConstants;
import com.itlong.cloud.sdk.dao.ISDKServerOldRoomDao;
import com.itlong.cloud.sdk.service.ISDKServerOldRoomService;
import com.itlong.cloud.thrown.DataAccessException;
import com.itlong.cloud.utils.data.handler.SqlUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * <desc>
 *
 * </desc>
 *
 * @createDate 2017/11/8
 */
@Service
public class SDKServerOldRoomServiceImpl implements ISDKServerOldRoomService {

    @Autowired
    ISDKServerOldRoomDao iSDKRoomDao;

    /**
     * <desc>
     *      根据参数字段查询room_info信息
     * <desc/>
     * @param  param  查询参数集
     * @return List<RoomInfoPO>    返回对象集
     * @author Biao.R
     * @createDate 2017/11/8
     */
    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public List<RoomInfoPO> getRoomByParam(Map<String, Object> param) {
        if(param.size()>0){
            return iSDKRoomDao.getRoomByParam(param);
        }
        return null;
    }

    /**
     * <desc>
     *      更新房间信息
     * <desc/>
     * @param   roomPO    待更新的PO对象
     * @return  Integer     更新数量
     * @author Biao.R
     * @createDate 2017/11/8
     */
    @Override
    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
    public Integer update(RoomInfoPO roomPO) {
        try {
            if(roomPO !=null){
               return iSDKRoomDao.update(SqlUtil.durableData(roomPO, PlatformConstants.TABLE_UPDATE));
            }
        } catch (Exception e) {
            throw new DataAccessException("【SDK_room_update】更新房间异常",e);
        }
        return null;
    }

    /**
     * <desc>
     *      保存房间信息
     * <desc/>
     * @param   roomPO    待保存的PO对象
     * @return  Integer     保存数量
     * @author Biao.R
     * @createDate 2017/11/8
     */
    @Override
    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
    public Integer save(RoomInfoPO roomPO) {
        try {
            if(roomPO !=null){
                return iSDKRoomDao.save(SqlUtil.durableData(roomPO, PlatformConstants.TABLE_SAVE));
            }
        } catch (Exception e) {
            throw new DataAccessException("【SDK_room_update】更新房间异常",e);
        }
        return null;
    }

    /**
     * <desc>
     *      根据projectId,buildNum,unitNum和roomNum查询房间信息
     * <desc/>
     * @param       params      待查询的参数集
     * @return      符合的房间对象集
     * @author Biao.R
     * @createDate 2017/11/16
     */
    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public List<RoomInfoPO> getRoomByPiBnUnRn(Map<String, Object> params) {
        if(!params.isEmpty()){
        return iSDKRoomDao.getRoomByPiBnUnRn(params);
        }
        return null;
    }
}